﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;

namespace GataBaseSys
{
    public partial class Xiugai : System.Web.UI.Page
    {
        AuctionBLL bll = new AuctionBLL();
        AddressBLL addbll = new AddressBLL();
        CommodityBLL combll = new CommodityBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.Droplistdiqu.DataSource = addbll.auctions();
                this.Droplistdiqu.DataValueField = "AddressID";
                this.Droplistdiqu.DataTextField = "AddressCategory";
                this.Droplistdiqu.DataBind();

                this.Droplistleixing.DataSource = combll.auctions();
                this.Droplistleixing.DataTextField = "CommodityCategory";
                this.Droplistleixing.DataValueField = "CommodityID";
                this.Droplistleixing.DataBind();

                if (Session["id"] != null)
                {
                    int fid = Convert.ToInt32(Session["id"]);
                    Auction au = bll.Fid(fid);
                    this.title.Value = au.AuctionName;
                    this.Image1.ImageUrl = au.AuctionPicture;
                    this.username.Value = au.AuctionIntroduce;
                    this.phone.Value = au.AuctionPrice.ToString();
                    this.Droplistzhuang.SelectedItem.Text = au.AuctionState;
                    this.Droplistdiqu.SelectedValue = au.AuctionCategory.ToString();
                    this.Droplistleixing.SelectedIndex = au.AuctionCode;
                    this.shangdate.Value = au.AuctionUpload.ToString("yyyy-MM-dd");
                    this.paimai.Value = au.AuctionAuction.ToString("yyyy-MM-dd");
                }
            }

        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            if (this.FileUpload1.HasFile)
            {
                var LuJing = Server.MapPath("~/Img/") + FileUpload1.FileName;
                this.FileUpload1.SaveAs(LuJing);
                this.Image1.ImageUrl = "../Img/" + FileUpload1.FileName;
            }
        }

        protected void BtuQue_Click1(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Session["id"]);
            if (id != 0)
            {
                Auction auc = bll.Fid(id);
                auc.AuctionID = id;
                auc.AuctionName = this.title.Value.Trim();
                auc.AuctionPicture = this.Image1.ImageUrl;
                auc.AuctionIntroduce = this.username.Value.Trim();
                auc.AuctionPrice =Convert.ToDecimal(this.phone.Value.Trim());
                auc.AuctionState = this.Droplistzhuang.SelectedItem.Text;
                auc.AuctionCategory = Convert.ToInt32(this.Droplistdiqu.SelectedValue);
                auc.AuctionCode = this.Droplistleixing.SelectedIndex;
                auc.AuctionUpload = Convert.ToDateTime(this.shangdate.Value.Trim().ToString());
                auc.AuctionAuction = Convert.ToDateTime(this.paimai.Value.Trim().ToString());
                if (bll.UpdateAuc(auc))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功')</script>");
                }
            }
        }
    }
}